package com.spike.service;

import com.spike.mapper.DeptMapper;
import com.spike.model.Dept;
import com.spike.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class DeptService {
    public List<Dept> findList() throws Exception {
        SqlSession sqlSession = new MyBatisUtils().getSqlSession();
        return sqlSession.getMapper(DeptMapper.class).findList();
    }
    public List<String> findDeptName() throws Exception {
        SqlSession sqlSession = new MyBatisUtils().getSqlSession();
        return sqlSession.getMapper(DeptMapper.class).findDeptName();
    }
    public Dept findById(int id) throws Exception {
        SqlSession sqlSession = new MyBatisUtils().getSqlSession();
        return sqlSession.getMapper(DeptMapper.class).findById(id);
    }
    public int updateDept(Dept dept) throws Exception {
        SqlSession sqlSession = new MyBatisUtils().getSqlSession();
        int i = sqlSession.getMapper(DeptMapper.class).updateDept(dept);
        sqlSession.commit();
        return i;
    }
    public int deleteDept(int id) throws Exception {
        SqlSession sqlSession = new MyBatisUtils().getSqlSession();
        int i = sqlSession.getMapper(DeptMapper.class).deleteDept(id);
        sqlSession.commit();
        return i;
    }
    public int addDept(Dept dept) throws Exception {
        SqlSession sqlSession = new MyBatisUtils().getSqlSession();
        int i = sqlSession.getMapper(DeptMapper.class).addDept(dept);
        sqlSession.commit();
        return i;
    }

    public List<Dept> findByNA(Dept dept) throws Exception {
        SqlSession sqlSession = new MyBatisUtils().getSqlSession();
        return sqlSession.getMapper(DeptMapper.class).findByNA(dept);
    }
    public int findIdByName(String name) throws Exception {
        SqlSession sqlSession = new MyBatisUtils().getSqlSession();
        return sqlSession.getMapper(DeptMapper.class).findIdByName(name);
    }
}
